package org.sport.dbImplement;

import org.sport.dbInterface.ActivityOperation;
import org.sport.model.entityModel.ActivitytableEntity;

import org.sport.model.entityModel.UsertableEntity;
import org.sport.repository.ActivitytableRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Allen on 2017/9/21.
 */
@Service
public class ActOpeImp implements ActivityOperation {



    @Autowired
    ActivitytableRepository activitytableRepository;

    @Override
    public boolean addOneAct(ActivitytableEntity activitytableEntity) {

        if(activitytableRepository.saveAndFlush(activitytableEntity) == null)
            return false;
        else
            return true;
    }

    @Override
    public boolean updateOneActContent(ActivitytableEntity activitytableEntity) {

        String theam            = activitytableEntity.getTheam();
        String location         = activitytableEntity.getLocation();
        String inviteeId        = activitytableEntity.getInviteeId();
        String status           = activitytableEntity.getStatus();
        String brief            = activitytableEntity.getBrief();
        Integer id              = activitytableEntity.getId();
        activitytableRepository.updateContentByActId(theam,location,inviteeId,status,brief,id);
        return true;
    }

    /*@Override
    public boolean delByUserActManager(UseractivitymanagerEntity userAM)
    {
        if(userAM != null)
        {
            ActivitytableEntity act;
            act = activitytableRepository.findOne(userAM.getActivitytableByActId().getId());
            if(act == null)
                System.out.println("找不到对应活动id");
            else {
                activitytableRepository.delete(act);
                activitytableRepository.flush();
            }
            return true;        //需要求证删除之后是否还需要查询数据
        }
        else
            return false;
    }*/

    @Override
    public ActivitytableEntity findByActId(ActivitytableEntity activitytableEntity) {
        return activitytableRepository.findOne(activitytableEntity.getId());
    }

    @Override
    public List<ActivitytableEntity> findByUserId(UsertableEntity usertableEntity) {

        return activitytableRepository.findActByUserId(usertableEntity);
    }

    @Override
    public List<ActivitytableEntity> findAllAct() {
        return activitytableRepository.findAll();
    }
}
